import React, { Component } from 'react'
import PubSub from 'pubsub-js'
export default class Main extends Component {
    state = {
        msg: ''
    }
    render() {
        return (
            <div className="result">{this.state.msg}</div>
        )
    }

    //组件挂载完毕的钩子
    componentDidMount(){
        PubSub.subscribe('keyword', (c, data) => {
            this.setState({
                msg: data
            })
        });
    }

    //组件将要卸载
    componentWillUnmount(){
        //取消订阅
        PubSub.unsubscribe('keyword');
    }
}
